﻿/// <reference path="PagerElement.js" />

var $PagerPosition = TA.Turbo.Common.PagerPosition =
{
	None: 0,
	Top: 1 << 0,
	Bottom: 1 << 1,
	TopAndBottom: 1 << 0 | 1 << 1
};
var $PagerDisplayMode = TA.Turbo.Common.PagerDisplayMode =
{
	ShowAlways: 0,
	ShowWhenOneOrMore: 1,
	ShowWhenTwoOrMore: 2
};


var $PagerSettings = TA.Turbo.Controls.PagerSettings = function PagerSettings()
{
	this.First = new $PagerElement();
	this.First.Text = this.First.DefaultText = "<<";

	this.Previous = new $PagerElement();
	this.Previous.Text = this.Previous.DefaultText = "<";

	this.PreviousGroup = new $PagerElement();
	this.PreviousGroup.Text = this.PreviousGroup.DefaultText = "...";

	this.NextGroup = new $PagerElement();
	this.NextGroup.Text = this.NextGroup.DefaultText = "...";

	this.Next = new $PagerElement();
	this.Next.Text = this.Next.DefaultText = ">";

	this.Last = new $PagerElement();
	this.Last.Text = this.Last.DefaultText = ">>";

	this.Normal = new $PagerElement();
	this.Normal.Text = this.Normal.DefaultText = "###";
}
$PagerSettings.Inherit(BaseJsonSerializable);
$PagerSettings.Inherit(BaseJsonDeserializable);

if (____a)
{
	$PagerSettings.prototype = new BaseJsonSerializable();


	$PagerSettings.prototype.First = new $PagerElement();
	$PagerSettings.prototype.Previous = new $PagerElement();
	$PagerSettings.prototype.PreviousGroup = new $PagerElement();
	$PagerSettings.prototype.Next = new $PagerElement();
	$PagerSettings.prototype.NextGroup = new $PagerElement();
	$PagerSettings.prototype.Last = new $PagerElement();
	$PagerSettings.prototype.Normal = new $PagerElement();
}

$PagerSettings.prototype.Size = 0;
$PagerSettings.prototype.ButtonCount = 10;
$PagerSettings.prototype.Position = $PagerPosition.Top;
$PagerSettings.prototype.DisplayMode = $PagerDisplayMode.ShowAlways;

$PagerSettings.prototype.ButtonHref = "";
$PagerSettings.prototype.ButtonHrefJS = "";

$PagerSettings.prototype.get_IsDirty = function get_IsDirty()
{
	return this.First.get_IsDirty()
		|| this.Previous.get_IsDirty()
		|| this.PreviousGroup.get_IsDirty()
		|| this.NextGroup.get_IsDirty()
		|| this.Next.get_IsDirty()
		|| this.Last.get_IsDirty()
		|| this.Normal.get_IsDirty()
		|| this.Size != 0
		|| this.ButtonCount != 10
		|| this.Position != $PagerPosition.Top
		|| this.DisplayMode != $PagerDisplayMode.ShowAlways
		|| !String.IsNullOrEmpty(this.ButtonHref)
		|| !String.IsNullOrEmpty(this.ButtonHrefJS);
}
$PagerSettings.prototype.SerializeContents = function SerializeContents(jw)
{
	if (____a)
		jw = new JsonWriter();

	if (this.First.get_IsDirty())
		jw.Property("F", this.First);
	if (this.Previous.get_IsDirty())
		jw.Property("P", this.Previous);
	if (this.PreviousGroup.get_IsDirty())
		jw.Property("PG", this.PreviousGroup);
	if (this.NextGroup.get_IsDirty())
		jw.Property("NG", this.NextGroup);
	if (this.Next.get_IsDirty())
		jw.Property("N", this.Next);
	if (this.Last.get_IsDirty())
		jw.Property("L", this.Last);
	if (this.Normal.get_IsDirty())
		jw.Property("R", this.Normal);
	if (this.Size != 0)
		jw.Property("S", this.Size);
	if (this.ButtonCount != 10)
		jw.Property("B", this.ButtonCount);
	if (this.Position != $PagerPosition.Top)
		jw.Property("O", this.Position);
	if (this.DisplayMode != $PagerDisplayMode.ShowAlways)
		jw.Property("M", this.DisplayMode);
		
	if (!String.IsNullOrEmpty(this.ButtonHref))
		jw.Property("H", this.ButtonHref);
	if (!String.IsNullOrEmpty(this.ButtonHrefJS))
		jw.Property("J", this.ButtonHrefJS);
}
$PagerSettings.prototype.DeserializeContent = function DeserializeContent(prShortName, value)
{
	switch (prShortName)
	{
		case "F":
			this.First = new $PagerElement();
			this.First.Text = this.First.DefaultText = "<<";
			this.First.Deserialize(value);
			break;
		case "P":
			this.Previous = new $PagerElement();
			this.Previous.Text = this.Previous.DefaultText = "<";
			this.Previous.Deserialize(value);
			break;
		case "PG":
			this.PreviousGroup = new $PagerElement();
			this.PreviousGroup.Text = this.PreviousGroup.DefaultText = "...";
			this.PreviousGroup.Deserialize(value);
			break;
		case "NG":
			this.NextGroup = new $PagerElement();
			this.NextGroup.Text = this.Next.DefaultText = "...";
			this.NextGroup.Deserialize(value);
			break;
		case "N":
			this.Next = new $PagerElement();
			this.Next.Text = this.Next.DefaultText = ">";
			this.Next.Deserialize(value);
			break;
		case "L":
			this.Last = new $PagerElement();
			this.Last.Text = this.Last.DefaultText = ">>";
			this.Last.Deserialize(value);
			break;
		case "R":
			this.Normal = new $PagerElement();
			this.Normal.Text = this.Normal.DefaultText = "###";
			this.Normal.Deserialize(value);
			break;
		case "S":
			this.Size = value; break;
		case "B":
			this.ButtonCount = value; break;
		case "O":
			this.Position = value; break;
		case "M":
			this.DisplayMode = value; break;

		case "H":
			this.ButtonHref = value; break;
		case "J":
			this.ButtonHrefJS = value; break;
	}
}
